﻿var DBPool=require('../util/DBpool');
module.exports={
    //这个是登陆
    login:function (user,callback) {
        console.log('here DAO');
        var sql='select username,usercode,userno from t_userinfo where tel=?';
        DBPool.getConnection(function (client) {
            client.query(sql,[user.mobile],function (error,result) {
                if(error){
                    console.log(error.message);
                    return;
                }
                callback(result);
                client.release();

            });
        });
    },
    //这个是注册
    register:function (user,callback){
            var sql='insert into t_userinfo (tel,usercode,username) values (?,?,?)';

            DBPool.getConnection(function (client) {
                client.query(sql,[user.mobile,user.password,user.nickname],function (error,result) {
                    if(error){
                        console.log(error.message);
                        return;
                    }
                    console.log(JSON.stringify(result));
                    callback(result);
                    client.release();

                });
            });
    },
    //这个是注册时检查有没有重复用户
    //check:function (mobile,callback){
    //    sql='select count(*) num from t_userinfo where tel=?';
    //    DBPool.getConnection(function (client) {
    //        client.query(sql,[mobile],function (error,result) {
    //            if(error){
    //                console.log(error.message);
    //                return;
    //            }
    //            console.log(JSON.stringify(result));
    //            callback(result);
    //            client.release();
    //
    //        });
    //    });
    //},




    check:function (nickname,mobile,callback){
        var sql='select count(*) num from t_userinfo where username=? || tel=?';
        DBPool.getConnection(function (client) {
            client.query(sql,[nickname,mobile],function (error,result) {
                if(error){
                    console.log(error.message);
                    return;
                }
                console.log(JSON.stringify(result));
                callback(result);
                client.release();

            });
        });
    }
};
